package com.ztools.common.config.rabbitMq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 一口香菜
 * @Date: 2023/3/24  12:42
 * @Version 1.0
 * 消息队列和交换机绑定类
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 队列和订单绑定关系
     *
     * @param queue    queue
     * @param exchange exchange
     * @return Binding
     */
    @Bean
    public Binding bindBootQueueExchange(@Qualifier("orderQueue") Queue queue, @Qualifier("topicExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("order.*");
    }

    @Bean
    public Binding bindCardQueueExchange(@Qualifier("openCardQueue") Queue queue, @Qualifier("topicExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("card.open.*");
    }

    /**
     * 绑定死信队列
     *
     * @param queue    queue
     * @param exchange exchange
     * @return Binding
     */
    @Bean
    public Binding bindDxlQueueExchange(@Qualifier("dlxQueue") Queue queue, @Qualifier("dlxExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("dlx.*");
    }
}
